package com.xiaolin.spring.validate;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.DataBinder;

/**
 * @ClassName PersonValidatorTest
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/11/8
 * @Version 1.0
 */
@Slf4j
public class PersonValidatorTest {
    public static void main(String[] args) {
        // 数据封装
        Person person=new Person();
        person.setAge(0);
        person.setName("小林");
        // 数据绑定
        DataBinder dataBinder = new DataBinder(person);
        // 设置校验器
        dataBinder.setValidator(new PersonValidator());
        // 校验
        dataBinder.validate();
        // 输出校验结果
        BindingResult bindingResult = dataBinder.getBindingResult();
        log.info("结果：{}",bindingResult);

    }
}
